import list from "./page.json"
import type {MockMethod} from "vite-plugin-mock";
import success from "../success.json"
import group from "./group.json"
import {findItem} from "../utils";

export default [
    {
        url: "/role/group/groupRoleTree",
        method: "post",
        response: () => {
            return list;
        }
    },
    {
        url: "/role/detail",
        method: "get",
        response: ({query}: any) => {
            //console.log(query.id);
            let info = findItem(list.data, query.id);
            let infoResult = null;
            if (info) {
                infoResult = JSON.parse(JSON.stringify(info));
            }
            if (info && info.children) {
                infoResult.children = null;
            }
            infoResult.menuIdList = ["30"];
            infoResult.roleId = infoResult.id
            infoResult.roleName = infoResult.name
            infoResult.roleGroupId = infoResult.parentId;
            infoResult.roleOrder = infoResult.sort;

            delete infoResult.id
            delete infoResult.name
            delete infoResult.parentId
            delete infoResult.sort

            let result = JSON.parse(JSON.stringify(success));
            // @ts-ignore
            result.data = infoResult;
            return result;
        }
    },
    {
        url: "/role/save",
        method: "post",
        response: () => {
            return success;
        }
    },
    {
        url: "/role/delete/:id",
        method: "delete",
        response: () => {
            return success;
        }
    },
    {
        url: "/role/group/list",
        method: "get",
        response: () => {
            return group;
        }
    },
    {
        url: "/role/group/detail",
        method: "get",
        response: ({query}: any) => {
            let info = findItem(list.data, query.id);
            let infoResult = null;
            if (info) {
                infoResult = JSON.parse(JSON.stringify(info));
            }
            if (info && info.children) {
                infoResult.children = null;
            }
            let result = JSON.parse(JSON.stringify(success));
            infoResult.roleGroupId = infoResult.id;
            infoResult.groupName = infoResult.name;
            infoResult.groupOrder = infoResult.sort;

            delete infoResult.id
            delete infoResult.name
            delete infoResult.children
            delete infoResult.type
            delete infoResult.sort
            // @ts-ignore
            result.data = infoResult;
            return result;
        }
    },
    {
        url: "/role/group/save",
        method: "post",
        response: () => {
            return success;
        }
    },
    {
        url: "/role/group/delete/:id",
        method: "delete",
        response: () => {
            return success;
        }
    },
] as MockMethod[];
